{% extends "base.html" %}
{% block title %}{% endblock %}
{% block content %}
<br>
<button class="layui-btn  layui-btn-normal" id="add" type="button">
    <i class="layui-icon"></i> 创建项目
</button>

<script type="text/html" id="filemange_v1">
    <button type="button"  class="layui-btn layui-btn-xs layui-btn-danger" lay-event="getNode">更新</button>

</script>
<hr class="layui-bg-gray">
<table class="layui-hide" id="projectCache" lay-filter="projectCache"></table>
<script>
    layui.use(['table','code'], function(){
          var table = layui.table
          ,form = layui.form;
          var $= layui.jquery;
          var loading = layer.load();
          var  options = {
                elem:'#projectCache',
                skin:"line",
                page:true,
                limit:10,
                limits:[10,20,30],
                height: 'full-200',
                toolbar: true,
                url:'/project/all',
                where:{
                },
                response:{
                    statusName:'errorCode',
                    statusCode:'',
                    dataName:'data'
                },
                cols:[[
                      {field: 'id', title: 'id',sort:true,width:80}
                      ,{field: 'project_name', title: 'project_name',sort:true,edit:'text'}
                      ,{field: 'last_time', title: 'last_time',sort:true}
                      ,{fixed: 'right', title:'', toolbar: '#filemange_v1',width:150}

                ]],
                id:'projectCache',
                done:function(res,cur,count){
                    layer.close(loading);
                }
              };
          var tableIns = table.render(options);
          //点击添加页面

          $('#add').on('click',function(){


                layer.open({
                            type:2,
                            content:'/project/manage',
                            area:['430px','150px'],
                            //offset: ['231px','307px'],
                            title:"创建项目",
                            closeBtn:1,
                            shade: 0,
                            shadeClose:true,
                            cancel: function(index, layero){
                                tableIns.reload(options);
                            }
                });
                return false;

          });
          table.on('row(projectCache)', function(obj){
                obj.tr.css("background","#eeeeee");
          });

          table.on('tool(projectCache)', function(obj){

                if(obj.event === 'getNode'){
                    $.ajax({
                        //发出请求
                        type:"POST",
                        url:"/project/manage",
                        contentType: 'application/json; charset=utf-8',
                        dataType:"json",
                        data:JSON.stringify(obj.data),
                        success: function(result){
                            if(result.id){
                                layer.msg("保存成功!");
                                tableIns.reload(options);
                            }else{
                                layer.msg("项目名称已经存在!");
                            }
                        }
                    });

                }
                return false;

          });

          form.render();
          layer.close(loading);
    });
</script>

{% endblock %}